package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.GroundItems;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Players;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSModel;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

public class DrawItems
  implements PaintListener
{
  private MethodContext ctx;

  public DrawItems(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics) {
    if (!this.ctx.game.isLoggedIn())
      return;
    RSPlayer localRSPlayer = this.ctx.players.getMyPlayer();
    if (localRSPlayer == null)
      return;
    FontMetrics localFontMetrics = paramGraphics.getFontMetrics();
    RSTile localRSTile = localRSPlayer.getLocation();
    int i = localRSTile.getX();
    int j = localRSTile.getY();
    int k = localFontMetrics.getHeight();
    for (int m = i - 25; m < i + 25; m++)
      for (int n = j - 25; n < j + 25; n++) {
        Point localPoint = this.ctx.calc.tileToScreen(new RSTile(m, n));
        if (!this.ctx.calc.pointOnScreen(localPoint)) {
          continue;
        }
        RSGroundItem[] arrayOfRSGroundItem = this.ctx.groundItems.getAllAt(m, n);
        if (arrayOfRSGroundItem.length > 0) {
          RSModel localRSModel = arrayOfRSGroundItem[0].getModel();
          if (localRSModel != null) {
            paramGraphics.setColor(Color.BLUE);
            for (Polygon localPolygon : localRSModel.getTriangles()) {
              paramGraphics.drawPolygon(localPolygon);
            }
          }
        }
        for (int i1 = 0; i1 < arrayOfRSGroundItem.length; i1++) {
          paramGraphics.setColor(Color.RED);
          paramGraphics.fillRect((int)localPoint.getX() - 1, (int)localPoint.getY() - 1, 2, 2);
          ??? = "" + arrayOfRSGroundItem[i1].getItem().getID();
          ??? = localPoint.y - k * (i1 + 1) + k / 2;
          ??? = localPoint.x - localFontMetrics.stringWidth((String)???) / 2;
          paramGraphics.setColor(Color.green);
          paramGraphics.drawString((String)???, ???, ???);
        }
      }
  }
}